package demo3;

class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println(name + "吃饭");
    }
}
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);//alt +回车
    }
    public void bark() {
        System.out.println(this.name + " 旺旺叫！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃狗粮...");
    }
}
class Bird extends Animal {
    public Bird(String name, int age) {
        super(name, age);
    }

    public void qiqi() {
        System.out.println(this.name +" 吱吱叫！");
    }

    public void fly() {
        System.out.println(this.name+" 正在飞！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+"正在吃鸟粮...");
    }
}
public class Test {

    public static void main5(String[] args) {
        Animal animal1 = new Dog("小黄",10);
        if(animal1 instanceof Dog){//存在风险用instanceof判断
            Dog dog = (Dog)animal1;//先转换成Dog类（向下转型）
            dog.bark();
        }
        if(animal1 instanceof Bird) {
            Bird bird2 = (Bird) animal1;
            bird2.fly();
        }else {
            System.out.println("animal1 instanceof Bird not!");
        }

        /*System.out.println("=====");*/

        Animal animal2 = new Bird("小黄",10);
        Bird bird = (Bird)animal2;
        bird.fly();
        System.out.println("=====");

    }



    public static Animal func2() {
        return new Dog("小黄",10);
    }

    public static void func(Animal animal1) {
        animal1.eat();
    }

    public static void main2(String[] args) {
        Dog dog = new Dog("小黄",10);
        Bird bird = new Bird("小鸟",10);
        func(dog);
        func(bird);
    }

    public static int add(int a,int b) {
        return a+b;
    }

    public static int add(int a,int b,int c) {
        return a+b+c;
    }

    public static void main(String[] args) {
//        System.out.println(add(1, 2));
//        System.out.println(add(1, 2,3));
        /*Dog dog = new Dog();
        Animal animal = dog; */
        Animal animal1 = new Dog("小黄",10);
        animal1.eat();
        //animal1.bark();
    }
}